from django.db import models
from django.contrib.auth.models import User
from django.newforms import ModelForm

# Create your models here.

class Book(models.Model):
    title = models.CharField(max_length=50)
    author = models.CharField(max_length=20)
    publisher = models.CharField(max_length=30, blank=True)
    publish_date = models.DateField(blank=True)
    buy_date = models.DateField(auto_now_add=True)
    buyer = models.ForeignKey(User, related_name = 'buy_books')
    holder = models.ForeignKey(User, related_name = 'hold_books')

    class Admin:
        pass;

    class Meta:
        ordering = ('-buy_date',)

    def __str__(self):
        return self.title

    def __unicode__(self):
        return self.title

class BookForm(ModelForm):
    class Meta:
        model = Book